// src/main.js
import { createApp } from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import router from './router'
import 'element-plus/dist/index.css'

// 创建Vue实例
const app = createApp(App)

// 注册Element Plus
app.use(ElementPlus, {
  locale: zhCn
})
// 注册Element Plus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 配置全局axios实例
import axios from '@/components/plugins/axios'
app.use(axios)

// 配置全局loading实例
import loading from '@/components/plugins/loading'
app.use(loading)

// 全局加载组件
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
// 配置 NProgress
NProgress.configure({
  minimum: 0.1, // 最小百分比
  easing: 'ease', // 动画效果
  speed: 500, // 动画速度（毫秒）
  showSpinner: false, // 是否显示加载图标
  trickle: true, // 是否自动增加进度
  trickleSpeed: 200 // 自动增加速度
})
app.config.globalProperties.$NProgress = NProgress

// 全局消息提醒
import message from '@/components/messageTip/index.js' // 引入封装的方法
app.use(message)

//全局路径跳转
import ToPath from '@/components/plugins/ToPath/index.js'
app.use(ToPath, { router })

// 全局注册指令
import resizeDirective from '@/components/plugins/utils/resizeDirective.js'
app.directive('resize', resizeDirective)

// 注册路由
app.use(router)
// 挂载到DOM
app.mount('#app')
